package org.nox.helloseries.configuration;

import java.io.IOException;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CustomConfiguration
{
    private static final Logger LOG = LoggerFactory.getLogger( CustomConfiguration.class );

    private static final String PATH_CONF = "conf/conf.ini";

    private Properties p = new Properties();

    private static CustomConfiguration _instance;

    public final synchronized static CustomConfiguration get()
    {
        if ( _instance == null )
        {
            _instance = new CustomConfiguration();
        }
        return _instance;
    }

    private CustomConfiguration()
    {
        super();
        try
        {
            p.load( this.getClass().getClassLoader().getResourceAsStream( PATH_CONF ) );
        }
        catch ( IOException e )
        {
            LOG.error( "", e );
        }
    }

    public String getString( CustomConfigurationKey key )
    {
        return p.getProperty( key.getValue() );
    }

    public Integer getInteger( CustomConfigurationKey key )
    {
        return Integer.parseInt( p.getProperty( key.getValue() ) );
    }

    public Double getDouble( CustomConfigurationKey key )
    {
        return Double.parseDouble( p.getProperty( key.getValue() ) );
    }
}
